import { ActionContext } from 'vuex'
import { Setting } from '../interface/setting'

const state: Setting = {
  tagsView: []
}

const mutations = {
  CHANGE_SETTING: (
    state: Setting,
    {
      key,
      value
    }: {
      key: keyof Setting
      value: any
    }
  ) => {
    if (Object.prototype.hasOwnProperty.call(state, key)) {
      state[key] = value
    }
  }
}

const actions = {
  changeSetting({ commit }: ActionContext<Setting, any>, data: { [key: string]: any }) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
